function lpostd = lmj_postmin(parest, parvec, parposest, indmat, funcmod, Y, trainvec, prpar, prss, solveopt, addsol, ssposest, flag_transform)
% ======================================================================
% LMJ_POSTMIN.M
% follow the structure of GENSYSPOST_VEC by Alejandro Justiniano (C)
% IN addition to putting priors on parameters, our current model put
% priors on steady state values.
%
% =======================================================================
lpostd=1e20;
if nargin < 13; flag_transform = 1; end;
if flag_transform ==1 
    [parest,flag_c]=check_min(parest,indmat);
    if flag_c==0;disp('Problems with transformed coefficients');return;end
end
parvec(parposest)=parest;

%% Likelihood
[likel, ssvec] = lmj_likel(parest, parvec, parposest, funcmod, Y, trainvec,solveopt, addsol);
% if likel < 1e-10 
%     return 
% end 
if isempty(ssvec); return; end
%% Prior Density of Parameters
lpriord=sum(priordens(parvec, prpar.prior, prpar.alphap, prpar.betap, prpar.lbnd, prpar.ubnd));
if isinf(abs(lpriord))==1;return;end
%% Prior Density on Steady State
lpriord_ss = sum(priordens(ssvec(ssposest), prss.prior, prss.alphap, prss.betap, prss.lbnd, prss.ubnd));
if isinf(abs(lpriord_ss))==1;return;end

%% log likelihood
lpostd = -(lpriord + lpriord_ss + likel);
%disp( sprintf('lpostd=%2.10g',lpostd) ); 
end